package com.zw.pdm.module.basic.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.basic.Process;
import com.zw.pdm.entity.basic.*;
import com.zw.pdm.entity.sys.User;
import com.zw.pdm.module.basic.service.CraftDictionariesServer;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 工艺字典表：工艺路线、工艺审核人
 * @Author mayongfeng
 * @Date 8:54 2020/12/3
 * @Description
 *
 **/
@Controller
@RequestMapping("/craft/dict")
@SuppressWarnings("all")
public class CraftDictionariesController extends BaseController {

    @Autowired
    private CraftDictionariesServer craftDictionariesServer;


    /**************************************************以下是工艺路线的数据字典配置****************************************/

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺路线跳转页面
     *
     **/
    @GetMapping("route")
    @RequiresPermissions({"craft:route7:view"})
    public String routePage() {
        return "basic/dict/comRoutePage";
    }


    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺路线字典查询
     *
     **/
    @ResponseBody
    @PostMapping("route/list")
    @RequiresPermissions({"craft:route7:view"})
    public JsonResult routeList(Route route, Model model) {
        startPage();
        List<Route> allCraftDiction = craftDictionariesServer.findAllCraftDiction(route);
        return jsonResult(allCraftDiction);
    }


    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺路线字典数据保存
     *
     **/
    @ResponseBody
    @PostMapping("route/save")
    @RequiresPermissions({"craft:route7:save"})
    public JsonResult routeSave(Route route) {
        Route routeCraftDiction = craftDictionariesServer.saveRouteCraftDiction(route);
        return isNotNull(routeCraftDiction);
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺路线字典数据修改
     *
     **/
    @ResponseBody
    @PostMapping("route/update")
    @RequiresPermissions({"craft:route7:update"})
    public JsonResult routeUpdate(Route route) {
         Route  routeCraftDiction = craftDictionariesServer.updateRouteCraftDiction(route);
        return isNotNull(routeCraftDiction);
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺路线字典数据删除
     *
     **/
    @ResponseBody
    @PostMapping("route/del")
    @RequiresPermissions({"craft:route7:del"})
    public JsonResult routeDel(Route route) {
        Route  routeCraftDiction = craftDictionariesServer.delRouteCraftDiction(route);
        return isNotNull(routeCraftDiction);
    }



    /**************************************************以下是工艺审核人的数据字典配置**************************************/



    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人数据字典跳转页面
     *
     **/
    @GetMapping("person")
    @RequiresPermissions({"craft:person7:view"})
    public String personPage(Model model) {
        model.addAttribute("depts",craftDictionariesServer.selectDeptAll(null));
        return "basic/dict/comPersonPage";
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人数据字典跳转页面
     *
     **/
    @ResponseBody
    @PostMapping("person/branch")
    @RequiresPermissions({"craft:person7:view"})
    public JsonResult personBranch(Integer pid) {
        List<Dept> depts = craftDictionariesServer.selectDeptAll(pid);
        return jsonResult(depts);
    }



    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人字典查询
     *
     **/
    @ResponseBody
    @PostMapping("person/list")
    @RequiresPermissions({"craft:person7:view"})
    public JsonResult personList(Person person) {
        startPage();
        List<Person> allCraftDiction = craftDictionariesServer.findAllPersonCraftDiction(person);
        return jsonResult(allCraftDiction);
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 通过员工编号查询员工信息
     *
     **/
    @ResponseBody
    @PostMapping("person/user")
    @RequiresPermissions({"craft:person7:view"})
    public JsonResult personUser(String code) {
        User allPersonUserCraftDiction = craftDictionariesServer.findAllPersonUserCraftDiction(code);
        if(null==allPersonUserCraftDiction){
            return isNotNull(allPersonUserCraftDiction);
        }else {
            return JsonResult.success("操作成功！",allPersonUserCraftDiction);
        }
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人字典数据保存
     *
     **/
    @ResponseBody
    @PostMapping("person/save")
    @RequiresPermissions({"craft:person7:save"})
    public JsonResult personSave(Person person) {
        Person personCraftDiction = craftDictionariesServer.savePersonCraftDiction(person);
        return isNotNull(personCraftDiction);
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人字典数据修改
     *
     **/
    @ResponseBody
    @PostMapping("person/update")
    @RequiresPermissions({"craft:person7:update"})
    public JsonResult personUpdate(Person person) {
        Person  personCraftDiction = craftDictionariesServer.updatePersonCraftDiction(person);
        return isNotNull(personCraftDiction);
    }

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工艺审核人字典数据删除
     *
     **/
    @ResponseBody
    @PostMapping("person/del")
    @RequiresPermissions({"craft:person7:del"})
    public JsonResult personDel(Person person) {
        Person personCraftDiction= craftDictionariesServer.delPersonCraftDiction(person);
        return isNotNull(personCraftDiction);
    }

    /**************************************************以下是工序的数据字典配置*******************************************/

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 工序数据字典跳转页面
     *
     **/
    @GetMapping("process")
    @RequiresPermissions({"craft:process7:view"})
    public String equPage() {
        return "basic/dict/comProcessPage";
    }

    /**
     * @Author mayongfeng
     * @Date 13:29 2020/12/7
     * @Description 工序列表展示页面
     *
     **/
    @ResponseBody
    @PostMapping("process/list")
    @RequiresPermissions({"craft:process7:view"})
    public JsonResult processList(Process process){
        List<Process> processList = craftDictionariesServer.findProcessList(process);
        return jsonResult(processList);

    }

    /**
     * @Author mayongfeng
     * @Date 14:09 2020/12/7
     * @Description 添加工序
     *
     **/
    @ResponseBody
    @PostMapping("process/save")
    @RequiresPermissions({"craft:process7:save"})
    public JsonResult saveProcess(Process process){
        Process saveProcess = craftDictionariesServer.saveProcess(process);
        return isNotNull(saveProcess);

    }

    /**
     * @Author mayongfeng
     * @Date 15:01 2020/12/7
     * @Description 修改工序
     *
     **/
    @ResponseBody
    @PostMapping("process/update")
    @RequiresPermissions({"craft:process7:update"})
    public JsonResult updatePorcess(Process process){
        Process updatePorcess = craftDictionariesServer.updatePorcess(process);
        return isNotNull(updatePorcess);

    }


    /**
     * @Author mayongfeng
     * @Date 15:51 2020/12/7
     * @Description 删除工序
     *
     **/
    @PostMapping("process/del")
    @RequiresPermissions({"craft:process7:del"})
    @ResponseBody
    public JsonResult delProcess(Process process){
        Process delProcess = craftDictionariesServer.delProcess(process);
        return isNotNull(delProcess);
    }





    /**************************************************以下是设备名称的数据字典配置****************************************/

    /**
     * @Author mayongfeng
     * @Date 8:57 2020/12/3
     * @Description 设备名称数据字典跳转页面
     *
     **/
    @GetMapping("equ")
    @RequiresPermissions({"craft:equ7:view"})
    public String processPage() {
        return "basic/dict/comEquPage";
    }


    /**
     * @Author mayongfeng
     * @Date 13:47 2020/12/7
     * @Description 设备名称数据列表查询
     *
     **/
    @ResponseBody
    @PostMapping("equ/list")
    @RequiresPermissions({"craft:equ7:view"})
    public JsonResult equList(Equ equ){
        List<Equ> equList = craftDictionariesServer.findAllEquList(equ);
        return jsonResult(equList);
    }

    /**
     * @Author mayongfeng
     * @Date 14:43 2020/12/7
     * @Description 添加设备名称
     *
     **/
    @ResponseBody
    @PostMapping("equ/save")
    @RequiresPermissions({"craft:equ7:save"})
    public JsonResult saveEqu(Equ equ){
        Equ saveEqu = craftDictionariesServer.saveEqu(equ);
        return isNotNull(saveEqu);
    }

    /**
     * @Author mayongfeng
     * @Date 15:15 2020/12/7
     * @Description 修改设备名称
     *
     **/
    @ResponseBody
    @PostMapping("equ/update")
    @RequiresPermissions({"craft:equ7:update"})
    public JsonResult updateEqu(Equ equ){
        Equ updateEqu = craftDictionariesServer.updateEqu(equ);
        return isNotNull(updateEqu);

    }

    /**
     * @Author mayongfeng
     * @Date 15:54 2020/12/7
     * @Description 删除设备名称
     *
     **/
    @ResponseBody
    @PostMapping("equ/del")
    @RequiresPermissions({"craft:equ7:update"})
    public JsonResult delEqu(Equ equ){
        Equ delEqu = craftDictionariesServer.delEqu(equ);
        return isNotNull(delEqu);
    }



}
